preserve
use  "dta/ISSP", clear

keep v3 v16 v25-v32 v56 v303 v324 v217 v218
keep if v3 == 30
keep if v324==36 | v324==83


g rich  = (v218 >= 8300) 
replace rich = . if v218 == .b | v218 == .c | v218 == .d


g v16g = (v16==1 | v16==2)
replace v16g = . if v16==.a | v16==.b

forvalues var = 25/32{
g v`var'g = (v`var'==1 | v`var'==2)
replace  v`var'g = . if v`var' == .a | v`var'==.b
}

g v56g = (v56==2)
replace v56g = . if v56 == .a | v56 ==.b

g french = (v324==36)


global X "v16g v56g v26g  v28g  v30g v31g v32g"
global bX "bv16g, bv56g, bv26g, bv28g, bv30g, bv31g, bv32g"
global vX "vv16g, vv56g, vv26g, vv28g, vv30g, vv31g, vv32g"

foreach v in $X{
replace `v' = `v'*100
}

label var v16g "Government redistribute wealth"
label var v56g "More social services vs reduce taxes"
label var v26g "health"
label var v28g "education"
label var v30g "retirement"
label var v31g "unemployment benefits"
label var v32g "culture, arts"

g rich_french = rich*french

foreach x in $X {
reg `x' french rich rich_french
}

* =================
* = SUMMARY STAT  =
* ==================

foreach x in $X {
reg `x'  if v324==83 & rich == 1
est store `x'
local name="`x'"
mat b`x'=_b[_cons]
mat v`x'= _se[_cons]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T1, replace   nose noaster bdec(2) onecol nor2 noobs ctitle("German-speaking", "Bottom-75% income")  

foreach x in $X {
reg `x'  if v324==83 & rich == 0
est store `x'
local name="`x'"
mat b`x'=_b[_cons]
mat v`x'= _se[_cons]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T1,   nose noaster bdec(2) onecol nor2 noobs ctitle("German-speaking", "Top-25% income")  


foreach x in $X {
reg `x' if v324==36 & rich == 1
est store `x'
local name="`x'"
mat b`x'=_b[_cons]
mat v`x'= _se[_cons]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T1, nose noaster bdec(2) onecol nor2 noobs ctitle("French-speaking", "Bottom-75% income")  

foreach x in $X {
reg `x' if v324==36 & rich == 0
est store `x'
local name="`x'"
mat b`x'=_b[_cons]
mat v`x'= _se[_cons]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T1, nose noaster bdec(2) onecol nor2 noobs ctitle("French-speaking", "Top-25% income")  


foreach x in $X {
reg `x' french
est store `x'
local name="`x'"
mat b`x'=_b[french]
mat v`x'= _se[french]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T1, onecol nor2 noobs bdec(2) ctitle("Difference French-German")  

foreach x in $X {
reg `x' rich
est store `x'
local name="`x'"
mat b`x'=_b[rich]
mat v`x'= _se[rich]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T1, onecol nor2 noobs bdec(2) ctitle("Difference Top-25%-Bottom-75% income")  

restore
